class Solution {
public:
    vector<int> getRow(int rowIndex) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        //int n = rowIndex;
        vector<int> old(rowIndex + 1);
        vector<int> cur(rowIndex + 1);

        cur[0] = 1;
        for (int i = 1; i <= rowIndex; ++i) {
            for (int j = 0; j < i; ++j) {
                old[j] = cur[j];
            }
            for (int j = 0; j <= i; ++j) {
                int t = 0;
                if (j - 1 >= 0) {
                    t += old[j - 1];
                }
                if (j < i) {
                    t += old[j];
                }
                cur[j] = t;
            }
        }
        return cur;
    }
};
